package com.example.demo_mvp.presenter;

import com.example.demo_mvp.base.presenter.BasePresenter;
import com.example.demo_mvp.contract.VideoContract;
import com.example.demo_mvp.entity.BaseResponse;
import com.example.demo_mvp.entity.VideoEntity;

import java.util.List;

import io.reactivex.Observer;
import io.reactivex.Scheduler;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * @author yaotianxue
 * @description
 * @date 2025/1/9
 */
public class VideoPresenter<V> extends BasePresenter<V> implements VideoContract.IVideoPresenter {
    private VideoContract.IVideoModel model;
    private VideoContract.IVideoView view;
    public VideoPresenter(VideoContract.IVideoModel model,VideoContract.IVideoView view){
       this.model = model;
       this.view = view;
   }
    @Override
    public void getVideoData() {
        model.getVideoData(1)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<BaseResponse<List<VideoEntity>>>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(BaseResponse<List<VideoEntity>> listBaseResponse) {
                        if(listBaseResponse.getCode() == 200){
                            view.showVideoData(listBaseResponse.getData());
                        }

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }
}
